#pragma once

#include <sstream>
#include <list>
#include "BaseDator.h"

template<class T>
class ListDator : public BaseDator
{
public:
	ListDator(list<T>& v) : values(v) { }
	BaseDator& operator =(string& s) { values.clear(); values.push_back(toVal(s)); return *this; }
	BaseDator& operator +=(string& s) { values.push_back(toVal(s)); return *this; }
	BaseDator& operator -=(string& s) { values.remove(toVal(s)); return *this; }
	bool operator ==(string& s) { return (find(values.begin(),values.end(),toVal(s))!=values.end()); }
	bool operator !=(string& s) { return !((*this)==s); }
  
	operator string() { return toString(values.back()); }
	operator list<T>&() { return values; }

	bool hasMultipleValues() { return true; }

	AUTO_SIZE;
protected:
	list<T>& values;
	T toVal(string& s)
	{
		stringstream str;
		str.unsetf(ios::skipws);
		str<<input;
		T res;
		str>>res;
		return res;
	}

	string toString(T& val)
	{
		stringstream str;
		str.unsetf(ios::skipws);
		str<<val;
		string res;
		str>>res;
		return res;
	}
};
